home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Games / ADoomPPC / src / amiga_system.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-04  |  6.4 KB  |  263 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <dos/dos.h>
  10. #include <dos/dosextens.h>
  11. #include <graphics/gfx.h>
  12. #include <graphics/gfxbase.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/intuitionbase.h>
  15. #include <proto/exec.h>
  16. //#include <powerup/clib/ppc_protos.h>
  17.  
  18. #include "doomdef.h"
  19. #include "m_misc.h"
  20. #include "i_system.h"
  21. #include "i_video.h"
  22. #include "i_sound.h"
  23.  
  24. #include "d_net.h"
  25. #include "g_game.h"
  26. #include "m_argv.h"
  27.  
  28. extern void ppctimer (unsigned int *time);
  29. extern double tb_scale_lo;
  30. extern double tb_scale_hi;
  31.  
  32. extern byte *vid_mem;
  33.  
  34. void amiga_getevents (void);
  35.  
  36. #define MIN_ZONESIZE  (2*1024*1024)
  37. #define MAX_ZONESIZE  (6*1024*1024)
  38.  
  39. /**********************************************************************/
  40.  
  41. extern struct ExecBase *SysBase;
  42. extern struct DosLibrary *DOSBase;
  43. struct GfxBase *GfxBase;
  44. struct IntuitionBase *IntuitionBase;
  45.  
  46. /**********************************************************************/
  47. // Called by DoomMain.
  48. void I_Init (void)
  49. {
  50.   if ((GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 39)) == NULL)
  51.     I_Error ("OpenLibrary(""graphics.library"", 39) failed");
  52.   if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 39)) == NULL)
  53.     I_Error ("OpenLibrary(""intuition.library"", 39) failed");
  54.  
  55.   I_InitSound ();
  56.   I_InitMusic ();
  57.   //  I_InitGraphics ();
  58. }
  59.  
  60. /**********************************************************************/
  61. // Called by startup code
  62. // to get the ammount of memory to malloc
  63. // for the zone management.
  64. byte*    I_ZoneBase (int *size)
  65. {
  66.   byte *zone;
  67.   ULONG memfree, largest;
  68.   int p;
  69.  
  70.   memfree = AvailMem (MEMF_FAST);
  71.   largest = AvailMem (MEMF_FAST | MEMF_LARGEST);
  72.   printf ("Memfree = %d, largest = %d\n", memfree, largest);
  73.  
  74.   p = M_CheckParm ("-heapsize");
  75.   if (p && p < myargc - 1) {
  76.  
  77.     *size = 1024 * atoi (myargv[p+1]);
  78.  
  79.   } else {
  80.  
  81.     if (largest > MAX_ZONESIZE + 65536 &&
  82.         memfree > MAX_ZONESIZE + (2 * 1024 * 1024))
  83.       *size = MAX_ZONESIZE;
  84.     else if (memfree < largest + (2 * 1024 * 1024))
  85.       *size = memfree - (2 * 1024 * 1024) - 65536;
  86.     else
  87.       *size = largest - 65536;
  88.  
  89.     if (*size < MIN_ZONESIZE)
  90.       I_Error ("Unable to allocate at least %d fastmem for zone management\n"
  91.                "while leaving 2Mb fastmem free\n"
  92.                "Fastmem free = %d, largest block = %d",
  93.                MIN_ZONESIZE, memfree, largest);
  94.   }
  95.  
  96.   if ((zone = (byte *)malloc(*size)) == NULL)
  97.     I_Error ("malloc() %d bytes for zone management failed", *size);
  98.  
  99.   printf ("I_ZoneBase(): Allocated %d bytes for zone management\n", *size);
  100.  
  101.   return zone;
  102. }
  103.  
  104. /**********************************************************************/
  105. // Called by D_DoomLoop,
  106. // returns current time in tics.
  107. int I_GetTime (void)
  108. {
  109.   unsigned int clock[2];
  110.   double currtics;
  111.   static double basetics=0.0;
  112.  
  113.   ppctimer (clock);
  114.   if (basetics == 0.0)
  115.     basetics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
  116.  
  117.   currtics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
  118.   return (int) (currtics-basetics);
  119. }
  120.  
  121. /**********************************************************************/
  122. //
  123. // Called by D_DoomLoop,
  124. // called before processing any tics in a frame
  125. // (just after displaying a frame).
  126. // Time consuming syncronous operations
  127. // are performed here (joystick reading).
  128. // Can call D_PostEvent.
  129. //
  130. void I_StartFrame (void)
  131. {
  132.   amiga_getevents ();
  133. }
  134.  
  135. /**********************************************************************/
  136. //
  137. // Called by D_DoomLoop,
  138. // called before processing each tic in a frame.
  139. // Quick syncronous operations are performed here.
  140. // Can call D_PostEvent.
  141. void I_StartTic (void)
  142. {
  143. }
  144.  
  145. /**********************************************************************/
  146. // Asynchronous interrupt functions should maintain private queues
  147. // that are read by the synchronous functions
  148. // to be converted into events.
  149.  
  150. // Either returns a null ticcmd,
  151. // or calls a loadable driver to build it.
  152. // This ticcmd will then be modified by the gameloop
  153. // for normal input.
  154. ticcmd_t    emptycmd;
  155. ticcmd_t* I_BaseTiccmd (void)
  156. {
  157.   return &emptycmd;
  158. }
  159.  
  160. /**********************************************************************/
  161. // Called by M_Responder when quit is selected.
  162. // Clean exit, displays sell blurb.
  163. void I_Quit (void)
  164. {
  165.   D_QuitNetGame ();
  166.   I_ShutdownSound();
  167.   I_ShutdownMusic();
  168.   M_SaveDefaults ();
  169.   I_ShutdownGraphics();
  170.  
  171.   if (GfxBase != NULL) {
  172.     CloseLibrary ((struct Library *) GfxBase);
  173.     GfxBase = NULL;
  174.   }
  175.   if (IntuitionBase != NULL) {
  176.     CloseLibrary ((struct Library *) IntuitionBase);
  177.     IntuitionBase = NULL;
  178.   }
  179.  
  180.   if (vid_mem != NULL)
  181.     PPCFreeVec (vid_mem);
  182.  
  183.   exit(0);
  184. }
  185.  
  186. /**********************************************************************/
  187. // Allocates from low memory under dos,
  188. // just mallocs under unix
  189. byte* I_AllocLow (int length)
  190. {
  191.   byte*    mem;
  192.  
  193.   if ((mem = (byte *)malloc (length)) == NULL)
  194.     I_Error ("Out of memory allocating %d bytes", length);
  195.   memset (mem,0,length);
  196.   return mem;
  197. }
  198.  
  199. /**********************************************************************/
  200. void I_Tactile (int on, int off, int total)
  201. {
  202.   // UNUSED.
  203.   on = off = total = 0;
  204. }
  205.  
  206. /**********************************************************************/
  207. void *I_malloc (size_t size)
  208. {
  209.   void *b;
  210.  
  211.   if ((b = malloc (size)) == NULL)
  212.     I_Error ("Out of memory allocating %d bytes", size);
  213.   return b;
  214. }
  215.  
  216. /**********************************************************************/
  217. void *I_calloc (size_t nelt, size_t esize)
  218. {
  219.   void *b;
  220.  
  221.   if ((b = calloc (nelt, esize)) == NULL)
  222.     I_Error ("Out of memory allocating %d bytes", nelt * esize);
  223.   return b;
  224. }
  225.  
  226. /**********************************************************************/
  227. void I_Error (char *error, ...)
  228. {
  229.   va_list    argptr;
  230.  
  231.   // Message first.
  232.   va_start (argptr, error);
  233.   fprintf (stderr, "Error: ");
  234.   vfprintf (stderr, error, argptr);
  235.   fprintf (stderr, "\n");
  236.   va_end (argptr);
  237.  
  238.   fflush (stderr);
  239.  
  240.   // Shutdown. Here might be other errors.
  241.   if (demorecording)
  242.     G_CheckDemoStatus ();
  243.  
  244.   D_QuitNetGame ();
  245.   I_ShutdownGraphics ();
  246.  
  247.   if (GfxBase != NULL) {
  248.     CloseLibrary ((struct Library *) GfxBase);
  249.     GfxBase = NULL;
  250.   }
  251.   if (IntuitionBase != NULL) {
  252.     CloseLibrary ((struct Library *) IntuitionBase);
  253.     IntuitionBase = NULL;
  254.   }
  255.  
  256.   if (vid_mem != NULL)
  257.     PPCFreeVec (vid_mem);
  258.  
  259.   exit (20);
  260. }
  261.  
  262. /**********************************************************************/
  263.